package com.example.stone.scissors.cloth;

import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	private Button jd, st, bu;
	private String user, result;
	private TextView dn, jg;
	Random r = new Random();
	int computer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		jd = (Button) this.findViewById(R.id.jd);
		st = (Button) this.findViewById(R.id.st);
		bu = (Button) this.findViewById(R.id.bu);
		dn = (TextView) this.findViewById(R.id.dn);
		jg = (TextView) this.findViewById(R.id.jg);

		jd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				user = "jd";
				computer = r.nextInt(3);
				dn.setText(str(computer, user));
				switch (computer) {
				case 0:
					jg.setText("电脑出石头");

					break;
				case 1:
					jg.setText("电脑出剪刀");

					break;

				case 2:
					jg.setText("电脑出布");
					break;

				}

			}
		});

		st.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				user = "st";
				computer = r.nextInt(3);
				dn.setText(str(computer, user));
				switch (computer) {
				case 0:
					jg.setText("电脑出石头");

					break;
				case 1:
					jg.setText("电脑出剪刀");

					break;

				case 2:
					jg.setText("电脑出布");
					break;

				}

			}
		});

		bu.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				user = "bu";
				computer = r.nextInt(3);
				dn.setText(str(computer, user));
				switch (computer) {
				case 0:
					jg.setText("电脑出石头");

					break;
				case 1:
					jg.setText("电脑出剪刀");

					break;

				case 2:
					jg.setText("电脑出布");
					break;

				}

			}
		});
	}

	public String str(int i, String s) {
		if (s == "st") {
			switch (i) {
			case 0:
				result = "平局";
				break;
			case 1:
				result = "我贏";
				break;
			case 2:
				result = "我輸";
				break;

			}
		} else if (s == "jd") {
			switch (i) {
			case 0:
				result = "我输";
				break;
			case 1:
				result = "平局";
				break;
			case 2:
				result = "我赢";
				break;

			}
		} else {
			switch (i) {
			case 0:
				result = "我赢";
				break;
			case 1:
				result = "我输";
				break;
			case 2:
				result = "平局";
				break;

			}
		}
		return result;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
